package javachess;

	import java.awt.BorderLayout;
	import java.awt.Color;
	import java.awt.Dimension;
	import java.awt.GridLayout;

	import javax.swing.JFrame;
	import javax.swing.JLayeredPane;
	import javax.swing.JPanel;

	public class ChessBoard extends JFrame
	{

		private static final long serialVersionUID = 1L;
		JLayeredPane layeredPane;
		JPanel chessBoard;

		public ChessBoard()
		{
			int width = 512; //screen width
			int height = 512;//screen height
			Dimension boardSize = new Dimension(width, height);

			layeredPane = new JLayeredPane();
			getContentPane().add(layeredPane);
			layeredPane.setPreferredSize(boardSize);


			chessBoard = new JPanel();
			layeredPane.add(chessBoard, JLayeredPane.DEFAULT_LAYER);
			chessBoard.setLayout(new GridLayout(8, 8));
			chessBoard.setPreferredSize(boardSize);
			chessBoard.setBounds(0, 0, boardSize.width, boardSize.height);

			for (int i = 0; i < 64; i++)
			{
				JPanel square = new JPanel(new BorderLayout());
				chessBoard.add(square);

				int row = (i / 8) % 2;
				if (row == 0)
					square.setBackground(i % 2 == 0 ? Color.black : Color.white);
				else
					square.setBackground(i % 2 == 0 ? Color.white : Color.black);
			}

		}

		public static void main(String[] args)
		{
			JFrame frame = new ChessBoard();
			frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			frame.pack();
			frame.setResizable(true);
			frame.setLocationRelativeTo(null);
			frame.setVisible(true);
		}
	}

